execute as @e[type=marker,tag=lightning_creator] at @s unless block ~ ~ ~ purple_glazed_terracotta run setblock ~ ~1 ~ air replace
execute as @e[type=marker,tag=lightning_creator] at @s unless block ~ ~ ~ purple_glazed_terracotta run kill @s
execute as @e[type=marker,tag=lightning_creator] at @s unless block ~ ~1 ~ stone_button run setblock ~ ~ ~ air replace
execute as @e[type=marker,tag=lightning_creator] at @s unless block ~ ~1 ~ stone_button run kill @s
execute as @e[type=marker,tag=lightning_creator] at @s if block ~ ~1 ~ stone_button[face=floor,powered=true] if entity @e[distance=..1.5,type=item_frame,nbt={Tags:["wire"]},tag=hasPower] positioned ~ ~4 ~ run summon lightning_bolt
execute as @e[type=marker,tag=lightning_creator] at @s if block ~ ~1 ~ stone_button[face=floor,powered=true] if entity @e[distance=..1.5,type=item_frame,nbt={Tags:["wire"]},tag=hasPower] run execute at @s if entity @e[type=!item_frame,distance=..1,type=!player] run tag @e[distance=..1.5,type=item_frame,nbt={Tags:["wire"]},tag=hasPower,limit=1,sort=random] remove hasPower
execute as @e[type=marker,tag=lightning_creator] at @s if block ~ ~1 ~ stone_button[face=floor,powered=true] run setblock ~ ~1 ~ stone_button[face=floor,powered=false]